home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / incl / LEDA / planar_map.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  5.5 KB  |  219 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  planar_map.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15.  
  16. #ifndef LEDA_PLANAR_MAP_H
  17. #define LEDA_PLANAR_MAP_H
  18.  
  19. #include <LEDA/graph.h>
  20.  
  21. class i_face;
  22.  
  23. typedef i_face* face;
  24.  
  25. class i_face {
  26.  
  27. friend class planar_map;
  28.  
  29.  edge      head;     // first edge of face
  30.  list_item loc;      // location in F_list
  31.  GenPtr    inf;      // user defined information
  32.  
  33.  planar_map*  g;     // face of (*g)
  34.  
  35.  
  36.  i_face(GenPtr x, planar_map* G) 
  37.  { 
  38.    inf = x ; 
  39.    head = nil; 
  40.    loc = nil; 
  41.    g = G;
  42.   }
  43.  
  44.  
  45.   LEDA_MEMORY(i_face)
  46.  
  47. FRIEND_INLINE planar_map* graph_of(face);
  48.  
  49. };
  50.  
  51. inline planar_map* graph_of(face f) { return f->g; }
  52.  
  53.  
  54.  
  55.  
  56.  
  57. extern int STRAIGHT_LINE_EMBEDDING(graph& G, node_array<int>& xcoord,
  58.                                             node_array<int>& ycoord);
  59.  
  60. class planar_map : public graph {
  61.  
  62. list<face>       F_list;
  63.  
  64. face  new_face(GenPtr i=0);
  65. void  del_face(face f) { F_list.del(f->loc); delete f; }
  66.  
  67. face& FACE(edge e) { return (face&)(e->data[0]);  }
  68.  
  69. virtual void copy_face_entry(GenPtr&)  const {}
  70. virtual void init_face_entry(GenPtr&)        {}
  71. virtual void clear_face_entry(GenPtr&) const {}
  72.  
  73. /* inherited from graph:
  74. virtual void copy_node_entry(GenPtr&)  const {}
  75. virtual void init_node_entry(GenPtr&)        {}
  76. virtual void clear_node_entry(GenPtr&) const {}
  77. */
  78.  
  79. virtual void print_face_entry(GenPtr&) const {}
  80.  
  81. public:
  82.  
  83.  
  84. planar_map(const graph&);
  85.  
  86. planar_map() {}
  87.  
  88. virtual ~planar_map() { clear(); }
  89.  
  90. void       clear();
  91.  
  92. void       init_entries();
  93.  
  94.  
  95. list<node> adj_nodes(face)   const;
  96. list<node> adj_nodes(node v) const { return graph::adj_nodes(v); }
  97.  
  98. list<edge> adj_edges(face)   const;
  99. list<edge> adj_edges(node v) const { return graph::adj_edges(v); }
  100.  
  101. const list<face>& all_faces()       const { return F_list; }
  102.  
  103. list<face> adj_faces(node)   const;
  104.  
  105. face       adj_face(edge e)  const { return face(e->data[0]); }
  106.  
  107. list<edge> triangulate();
  108.  
  109. edge reverse(edge e)         const { return edge(e->rev); }
  110.  
  111. edge first_face_edge(face f) const { return f->head; }
  112. edge succ_face_edge(edge e)  const { return cyclic_adj_succ(reverse(e)); } 
  113. edge pred_face_edge(edge e)  const { return reverse(cyclic_adj_pred(e)); } 
  114.  
  115. edge next_face_edge(edge e)  const  
  116. { e = succ_face_edge(e);
  117.   return (e==adj_face(e)->head) ? nil : e;
  118. }
  119.  
  120. face first_face() const { return F_list.head(); }
  121.  
  122. face next_face(face f) const
  123. { list_item it = F_list.succ(f->loc);
  124.   return (it) ? F_list.contents(it) : nil;
  125. }
  126.  
  127.  
  128. edge    new_edge(edge,edge,GenPtr=0);
  129. void    del_edge(edge,GenPtr=0);
  130.  
  131. edge    split_edge(edge,GenPtr=0);
  132.  
  133. node    new_node(const list<edge>&, GenPtr=0);
  134. node    new_node(face, GenPtr=0);
  135.  
  136. GenPtr& entry(face f)         { return f->inf; }
  137. GenPtr& entry(node v)         { return graph::entry(v); }
  138.  
  139. GenPtr  inf(face f)     const { return f->inf; }
  140. GenPtr  inf(node v)     const { return graph::inf(v); }
  141.  
  142. int     straight_line_embedding(node_array<int>& x, node_array<int>& y)
  143.                               { return STRAIGHT_LINE_EMBEDDING(*this,x,y); }
  144.  
  145.  
  146. };
  147.  
  148.  
  149. //------------------------------------------------------------------------------
  150. // PLANAR_MAP: generic planar map
  151. //------------------------------------------------------------------------------
  152.  
  153.  
  154. template <class vtype, class ftype>
  155.  
  156. class _CLASSTYPE PLANAR_MAP : public planar_map {
  157.  
  158. vtype X;
  159. ftype Y;
  160.  
  161. void init_node_entry(GenPtr& x)  { Init(X); x=Copy(X); }
  162. void init_face_entry(GenPtr& x)  { Init(Y); x=Copy(Y); }
  163.  
  164. void copy_node_entry(GenPtr& x)  const { x=Copy(ACCESS(vtype,x)); }
  165. void copy_face_entry(GenPtr& x)  const { x=Copy(ACCESS(ftype,x)); }
  166.  
  167. void clear_node_entry(GenPtr& x) const { Clear(ACCESS(vtype,x)); }
  168. void clear_face_entry(GenPtr& x) const { Clear(ACCESS(ftype,x)); }
  169.  
  170. void print_node_entry(ostream& o, GenPtr& x)  const
  171. { o << "("; Print(ACCESS(vtype,x),o); o << ")"; }
  172.  
  173. void print_edge_entry(ostream& o, GenPtr& x)  const
  174. { o << "(" << int(x) << ")"; }
  175.  
  176. public:
  177.  
  178.    vtype  inf(node v)    const   { return ACCESS(vtype,planar_map::inf(v)); }
  179.    ftype  inf(face f)    const   { return ACCESS(ftype,planar_map::inf(f)); }
  180.    vtype& entry(node v)          { return ACCESS(vtype,planar_map::entry(v)); }
  181.    ftype& entry(face f)          { return ACCESS(ftype,planar_map::entry(f)); }
  182.    vtype& operator[] (node v)    { return entry(v); }
  183.    ftype& operator[] (face f)    { return entry(f); }
  184.    void   assign(node v,vtype a) { planar_map::entry(v) = Copy(a); }
  185.    void   assign(face f,ftype a) { planar_map::entry(f) = Copy(a); }
  186.  
  187.    edge   new_edge(edge e1, edge e2)
  188.                           { return planar_map::new_edge(e1,e2,0); }
  189.    edge   new_edge(edge e1, edge e2, ftype a)
  190.                           { return planar_map::new_edge(e1,e2,Convert(a)); }
  191.  
  192.    edge   split_edge(edge e, vtype a)
  193.                           { return planar_map::split_edge(e,Convert(a)); }
  194.  
  195.    node   new_node(list<edge> el,vtype a)
  196.                           { return planar_map::new_node(el,Convert(a)); }
  197.  
  198.    node   new_node(face f,vtype a)
  199.                           { return planar_map::new_node(f,Convert(a)); }
  200.  
  201.    void print_node(node v) const { cout << "["; Print(inf(v)); cout << "]";}
  202.  
  203.    PLANAR_MAP(const GRAPH<vtype,ftype>& G) : planar_map((graph&)G)   {}
  204.    PLANAR_MAP() {}
  205.   ~PLANAR_MAP() { clear(); }
  206.  
  207. };
  208.  
  209.  
  210. #define forall_face_edges(e,F)\
  211. for(e=graph_of(F)->first_face_edge(F); e; e=graph_of(F)->next_face_edge(e)) 
  212.  
  213. #define forall_faces(f,G)\
  214. for(f=G.first_face(); f; f=G.next_face(f)) 
  215.  
  216.  
  217. #endif
  218.